home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / undogui.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-02-02  |  13.2 KB  |  433 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. /***************************************************************************
  8.  *   Copyright (C) 2005 by Riku Leino                                      *
  9.  *   tsoots@gmail.com                                                      *
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  *   This program is distributed in the hope that it will be useful,       *
  17.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  18.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  19.  *   GNU General Public License for more details.                          *
  20.  *                                                                         *
  21.  *   You should have received a copy of the GNU General Public License     *
  22.  *   along with this program; if not, write to the                         *
  23.  *   Free Software Foundation, Inc.,                                       *
  24.  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  25.  ***************************************************************************/
  26.  
  27. #ifndef UNDOGUI_H
  28. #define UNDOGUI_H
  29.  
  30. #include <QListWidgetItem>
  31. #include "scribusapi.h"
  32. #include "undoobject.h"
  33. #include "undostate.h"
  34. #include "scrpalettebase.h"
  35.  
  36. class QEvent;
  37. class QMenu;
  38. class QListWidget;
  39. class QCheckBox;
  40.  
  41.  
  42. /**
  43.  * @brief UndoGui is a virtual superclass for undo/redo widgets.
  44.  *
  45.  * UndoGui is a virtual superclass for all the classes that wants to represent
  46.  * undo/redo data. Subclasses must be registered to the UndoManager instance.
  47.  * Subclasses are expected to keep the whole stack with them and they must be
  48.  * able to work undo/redo situations by themselves. Only new undo actions and 
  49.  * steps (undo or redo) are reported back.
  50.  * 
  51.  * @sa UndoWidget
  52.  * @sa UndoPalette
  53.  *
  54.  * @author Riku Leino  tsoots@gmail.com
  55.  * @date December 2004
  56.  */
  57. class SCRIBUS_API UndoGui : public ScrPaletteBase
  58. {
  59.     Q_OBJECT
  60.  
  61. public:
  62.     /**
  63.      * @brief Creates a new UndoGui instance. 
  64.      * @param parent Parent object for UndoGui
  65.      * @param name Name of the object
  66.      * @param f widget flags
  67.      */
  68.     UndoGui(QWidget* parent = 0, const char* name = "UndoGui", Qt::WFlags f = 0);
  69.  
  70.     /** @brief Destroys the widget */
  71.     virtual ~UndoGui() {};
  72.  
  73.     /** @brief Empties the undo stack representation. */
  74.     virtual void clear() = 0;
  75.     
  76. public slots:
  77.     /**
  78.      * @brief Insert a new undo item.
  79.      *
  80.      * Insert a new undo item. After an undoable action has happened and
  81.      * if this UndoGui is registered to the UndoManager this slot will
  82.      * be used to register the action to the widget.
  83.      * @param target Target of the undo action
  84.      * @param state State describing the action
  85.      */
  86.     virtual void insertUndoItem(UndoObject* target, UndoState* state) = 0;
  87.  
  88.     /**
  89.      * @brief Insert a new redo item.
  90.      * @param target Target of the redo action
  91.      * @param state State describing the action
  92.      */
  93.     virtual void insertRedoItem(UndoObject* target, UndoState* state) = 0;
  94.  
  95.     /**
  96.      * @brief Update undo stack representation with number of steps.
  97.      * 
  98.      * When some other UndoGui subclass has received an undo request this
  99.      * slot is used to inform this UndoGui to update it's UndoStack 
  100.      * representation.
  101.      * @param steps Number of steps to take
  102.      */
  103.     virtual void updateUndo(int steps) = 0;
  104.  
  105.     /**
  106.      * @brief Update redo stack representation with number of steps.
  107.      * 
  108.      * When some other registered UndoGui subclass has received a redo
  109.      * request this slot is used to inform this UndoGui to update it's 
  110.      * undo stack representation.
  111.      * @param steps Number of steps to take
  112.      */
  113.     virtual void updateRedo(int steps) = 0;
  114.     
  115.     /**
  116.      * @brief Update the scrActions
  117.      */
  118.     virtual void updateUndoActions() = 0;
  119.     
  120.     /** @brief Clear the redo action items. */
  121.     virtual void clearRedo() = 0;
  122.  
  123.     /** @brief Remove the last (oldest) item from the undo stack representation. */
  124.     virtual void popBack() = 0;
  125. /* signals: do not implement these but emit when action happens
  126.     virtual void undo(int steps) = 0;
  127.     virtual void redo(int steps) = 0;
  128. */
  129. };
  130.  
  131. /*** UndoGui implementations **************************************************/
  132. /*** UndoWidget ***************************************************************/
  133.  
  134. /**
  135.  * @brief Tool bar buttons with pop up menus for undo and redo.
  136.  * 
  137.  * Provides tool bar buttons for undo and redo. There is also a pop up menu
  138.  * attached to these buttons for taking more than a single undo/redo step.
  139.  *
  140.  * @author Riku Leino tsoots@gmail.com
  141.  * @date December 2004
  142.  */
  143. class SCRIBUS_API UndoWidget : public UndoGui
  144. {
  145.     Q_OBJECT
  146.  
  147. private:
  148.     /** @brief Items visible in the pop up menus */
  149.     static const uint MENU_HEIGHT = 5;
  150.     std::vector<QString> undoItems;
  151.     std::vector<QString> redoItems;
  152.     /* BnF buttons
  153.     QToolButton* undoButton;
  154.     QToolButton* redoButton;
  155.     */
  156.     QMenu* undoMenu;
  157.     QMenu* redoMenu;
  158.     void updateUndoMenu();
  159.     void updateRedoMenu();
  160. public:
  161.     /** @brief Creates a new UndoWidget instance. */
  162.     UndoWidget(QWidget* parent = 0, const char* name = 0);
  163.  
  164.     /** @brief Destroys the widget */
  165.     virtual ~UndoWidget();
  166.  
  167.     /** @brief Empties the undo stack for this widget. */
  168.     void clear();
  169.     /**
  170.      * @brief Update the scrActions
  171.      */
  172.     virtual void updateUndoActions();
  173.         
  174. private slots:
  175.     void undoClicked();
  176.     void redoClicked();
  177.     void undoMenuClicked(QAction *id);
  178.     void redoMenuClicked(QAction *id);
  179. public slots:
  180.     /**
  181.      * @brief Insert a new undo item.
  182.      * 
  183.      * After an undoable action has happened and
  184.      * if this UndoGui is registered to the UndoManager this slot will
  185.      * be used to register the action to the widget.
  186.      * @param target Target of the undo action
  187.      * @param state State describing the action
  188.      */
  189.     void insertUndoItem(UndoObject* target, UndoState* state);
  190.  
  191.     /**
  192.      * @brief Insert a new redo item.
  193.      * @param target Target of the redo action
  194.      * @param state State describing the action
  195.      */
  196.     void insertRedoItem(UndoObject* target, UndoState* state);
  197.  
  198.     /**
  199.      * @brief Update undo stack representation with number of steps.
  200.      * 
  201.      * When some other UndoGui subclass has received an undo request this
  202.      * slot is used to inform this UndoGui to update it's UndoStack 
  203.      * representation.
  204.      * @param steps Number of steps to take
  205.      */
  206.     void updateUndo(int steps);
  207.  
  208.     /**
  209.      * @brief Update redo stack representation with number of steps.
  210.      * 
  211.      * When some other UndoGui subclass has received a redo request this
  212.      * slot is used to inform this UndoGui to update it's UndoStack 
  213.      * representation.
  214.      * @param steps Number of steps to take
  215.      */
  216.     void updateRedo(int steps);
  217.     
  218.     /** @brief Clear the redo action items. */
  219.     void clearRedo();
  220.     
  221.     /** @brief Remove the last (oldest) item from the undo stack representation. */
  222.     void popBack();
  223. signals:
  224.     /** 
  225.      * @brief Emitted when undo is requested.
  226.      * 
  227.      * When undo action is done by this class this signal is emitted.
  228.      * @param steps How many undo steps to take
  229.      */
  230.     void undo(int steps);
  231.  
  232.     /** 
  233.      * @brief Emitted when redo is requested.
  234.      * 
  235.      * When redo action is done by this class this signal is emitted.
  236.      * @param steps How many redo steps to take
  237.      */
  238.     void redo(int steps);
  239. };
  240.  
  241. /*** UndoPalette **************************************************************/
  242.  
  243. /**
  244.  * @brief UndoGui subclass which creates an undo history window
  245.  * 
  246.  * Provides a regular undo history window where a user can click on any action
  247.  * and related undo/redo steps are taken. Undo steps are represented as a 
  248.  * <code>QListBox</code> where there can be an image to describe the action
  249.  * visually, the name of the object and the name of the action per row.
  250.  *
  251.  * @author Riku Leino tsoots@gmail.com
  252.  * @date December 2004
  253.  */
  254. class SCRIBUS_API UndoPalette : public UndoGui
  255. {
  256.     Q_OBJECT
  257.  
  258. private:
  259.     int currentSelection;
  260.     int redoItems;
  261.     QListWidget* undoList;
  262.     QCheckBox* objectBox;
  263.     QPushButton* undoButton;
  264.     QPushButton* redoButton;
  265.     QKeySequence initialUndoKS;
  266.     QKeySequence initialRedoKS;
  267.     void updateList();
  268.     void removeRedoItems();
  269.     
  270. /*** UndoPalette::UndoItem ****************************************************/
  271.     
  272.     /** @brief UndoItem provides a custom QListBoxItem for the undo history view. */
  273.     class UndoItem : public QListWidgetItem
  274.     {
  275.     private:
  276.         /** @brief An icon for the undo target */
  277.         QPixmap *targetpixmap;
  278.         /** @brief An icon for the undo state (action) */
  279.         QPixmap *actionpixmap;
  280.         /** @brief Name of the target of the state (action) */
  281.         QString target;
  282.         /** @brief Undo action's name */
  283.         QString action;
  284.         /** @brief Description of the action */
  285.         QString description;
  286.         /** @brief Does this item describe an undo action if false it's a redo action */
  287.         bool isUndoAction_;
  288.     public:
  289.         /** @brief Create an empty UndoItem object */
  290.         UndoItem();
  291.         /**
  292.          * @brief Create a copy of <code>another</code> UndoItem instance.
  293.          * @param another UndoItem instance to copy
  294.          */
  295.         UndoItem(const UndoItem &another);
  296.         /**
  297.          * @brief Create an UndoItem instance.
  298.          * @param targetName Name of the target. Will appear on the first row of
  299.          * the item.
  300.          * @param actionName Name of the state (action). Will appear on the 
  301.          * second row of the item.
  302.          * @param actionDescription This description of the action will be used as a
  303.          * tooltip when the mouse cursor is over the item.
  304.          * @param actionPixmap Icon for the state (action). Will appear on front
  305.          * of the text parts.
  306.          * @param targetPixmap An icon for the undo target
  307.          */ 
  308.         UndoItem(const QString &targetName,
  309.                  const QString &actionName,
  310.                  const QString &actionDescription,
  311.                  QPixmap *targetPixmap,
  312.                  QPixmap *actionPixmap,
  313.                  bool isUndoAction,
  314.                  QListWidget * parent = 0);
  315.         ~UndoItem();
  316.         /*void paint(QPainter *painter);
  317.         int height(const QListWidget*) const;
  318.         int width(const QListWidget*) const;*/
  319.         QString getDescription();
  320.         bool isUndoAction();
  321.         void setUndoAction(bool isUndo);
  322.     };
  323.     
  324. /******************************************************************************/
  325.  
  326. private slots:
  327.     void undoClicked();
  328.     void redoClicked();
  329.     void undoListClicked(int i);
  330.     void showToolTip(QListWidgetItem *i);
  331.     void removeToolTip();
  332.     void objectCheckBoxClicked(bool on);
  333.  
  334. public:
  335.     /** 
  336.      * @brief Creates a new UndoPalette instance.
  337.      * 
  338.      * Creates a new UndoPalette instance. After creation of an UndoPalette it must
  339.      * be registered to the UndoManager with UndoManager's registerGui() method.
  340.      */
  341.     UndoPalette(QWidget* parent = 0, const char* name = 0);
  342.  
  343.     /** @brief Destroys the widget */
  344.     ~UndoPalette();
  345.     
  346.     virtual void changeEvent(QEvent *e);
  347.  
  348.     /** @brief Empties the undo stack for this widget. */
  349.     void clear();
  350.     /**
  351.      * @brief Update the scrActions
  352.      */
  353.     virtual void updateUndoActions();
  354.     
  355. public slots:
  356.     /** @brief Sets GUI strings on language change */
  357.     void languageChange();
  358.     
  359.     /**
  360.      * @brief Insert a new undo item.
  361.      * 
  362.      * Insert a new undo item. After an undoable action has happened and
  363.      * if this UndoGui is registered to the UndoManager this slot will
  364.      * be used to register the action to the widget.
  365.      * @param target Target of the undo action
  366.      * @param state State describing the action
  367.      */
  368.     void insertUndoItem(UndoObject* target, UndoState* state);
  369.  
  370.     /**
  371.      * @brief Insert a new redo item.
  372.      * @param target Target of the redo action
  373.      * @param state State describing the action
  374.      */
  375.     void insertRedoItem(UndoObject* target, UndoState* state);
  376.  
  377.     /**
  378.      * @brief Update undo stack representation with number of steps.
  379.      * 
  380.      * When some other UndoGui subclass has received an undo request this
  381.      * slot is used to inform this UndoGui to update it's UndoStack 
  382.      * representation.
  383.      * @param steps Number of steps to take
  384.      */
  385.     void updateUndo(int steps);
  386.  
  387.     /**
  388.      * @brief Update redo stack representation with number of steps.
  389.      * 
  390.      * When some other UndoGui subclass has received a redo request this
  391.      * slot is used to inform this UndoGui to update it's UndoStack 
  392.      * representation.
  393.      * @param steps Number of steps to take
  394.      */
  395.     void updateRedo(int steps);
  396.  
  397.     /** @brief Clear the redo action items. */
  398.     void clearRedo();
  399.     
  400.     /** @brief Remove the last (oldest) item from the undo stack representation. */
  401.     void popBack();
  402.  
  403.     /** @brief Recieve prefsChanged() signal to update shortcuts. */
  404.     void updateFromPrefs();
  405.  
  406. signals:
  407.  
  408.     /**
  409.      * @brief Emitted when undo behaviour should be changed from global undo
  410.      * @brief to object specific undo and other way around.
  411.      * @param isEnabled true if object specific undo is wanted, false for global undo
  412.      */
  413.     void objectMode(bool isEnabled);
  414.     /** 
  415.      * @brief Emitted when undo is requested.
  416.      * 
  417.      * When undo action is done by this class this signal is emitted.
  418.      * @param steps How many undo steps to take
  419.      */
  420.     void undo(int steps);
  421.  
  422.     /** 
  423.      * @brief Emitted when redo is requested.
  424.      * 
  425.      * When redo action is done by this class this signal is emitted.
  426.      * @param steps How many redo steps to take
  427.      */
  428.     void redo(int steps);
  429.  
  430. };
  431.  
  432. #endif // UNDOGUI_H
  433.